---
title: "Org. survey"
author: "Endre Borbáth, Swen Hutter"
date: "20.07.2025"
output:
  html_document:
    toc: yes
---

```{r, echo = F, message = F, include=FALSE}

# R setup

rm(list = ls()) 

library(foreign)
library(dplyr)
library(tidyr)
library(ggplot2)
library(stringr)
library(haven)
library(forcats)
library(lubridate)
library(texreg)
library(DescTools)
library(broom)
library(ordinal)
library(here)
set.seed(1991)

```

```{r, echo = F, message = F, include=FALSE}

plot_dat <- read_dta(here("study1.dta")) %>% 
  mutate(feld_small=as_factor(feld_small)) %>% 
  select(-id) %>% 
  mutate(counter=1) %>% 
  group_by(feld_small) %>% 
  mutate_at(vars("aktiv_freiw_dy", "activated", "deactivated", "counter"), ~sum(., na.rm=TRUE)) %>% 
  unique(.) %>% 
  drop_na(feld_small) %>% 
  mutate_at(vars("aktiv_freiw_dy", "activated", "deactivated"), ~.*100/counter) %>% 
  select(-counter) %>% 
  pivot_longer(cols=c("aktiv_freiw_dy", "activated", "deactivated"), names_to = "type", values_to = "share") %>% 
  mutate(type=case_when(type=="deactivated" ~ "De-activated volunteers",
                        type=="activated" ~ "Activated volunteers",
                        type=="aktiv_freiw_dy" ~ "Difficulty retaining volunteers")) %>% 
  mutate(type=factor(type, levels = c("Difficulty retaining volunteers", 
                                      "De-activated volunteers",
                                      "Activated volunteers"))) %>% 
  mutate(feld_small=fct_recode(feld_small, "Other"="Other services"))

```

```{r, include = T, echo = F, message = F, warning=FALSE, fig.width=5, fig.height=5}

ggplot(plot_dat, aes(y=share, x=feld_small)) +
  geom_bar(stat="identity", color="black") +
  facet_wrap(~type) +
  theme_linedraw() +
  ylab("Percentage of organizations") + 
  xlab("Type of organizations")

# ggsave(plot=last_plot(),
#        filename="org_volunteers.png",
#        path = fig_path,
#        width=6.5,
#        height=3,
#        scale=2.5,
#        dpi=400,
#        units="cm")  

```

